﻿Namespace Sigortali.GYS
	Module Functions


		Function Oku(ByVal Process As Token, ByVal rowid As Long) As Recordset
			Q("select * from sgys where rowid = :id")
			Return Process.OpenSQL("*", rowid)
		End Function

		Sub Kaydet(Token As Token, rowid As Integer, sno As Integer, gyskimlik As String, gysdtar As Date, gysadi As String, gyssoyadi As String,
			 gysacik As String, gysbastar As Date, gyssontar As Date, belgetur As String, belgeno As String, kaykul As String)
			Dim Rs As Recordset
			Token.BeginTran()
			If rowid = 0 Then
				Dim kimlik As String = Token.OpenSQL("select * from sgenel where sno = @sno", sno)("kimlik")
				Rs = Token.OpenSQL("select * from sgys where sno = @sno", sno)
				Rs.SetValues("sno,kimlik,gyskimlik,gysdtar,gysadi,gyssoyadi,gysacik",
				  sno, kimlik, gyskimlik, gysdtar, gysadi, gyssoyadi, gysacik)
				Rs.Save()
				rowid = Token.OpenSQL("select @@identity")(0)
			End If
			Rs = Token.OpenSQL("select * from sgysbelge where 1 = 0")
			Rs.AddNew()
			Rs.SetValues("gysrowid,belgetur,belgeno,bastar,sontar,islemtar,kaykul", rowid, belgetur, belgeno, gysbastar, gyssontar, Token.SysTime, kaykul)
			Rs.Save()
			Rs = Token.OpenSQL("select * from sgys where rowid = @rowid", rowid)
			Rs.SetValues("gysbastar,gyssontar,islemtar,kaykul", gysbastar, gyssontar, Token.SysTime, kaykul)
			Rs.Save()
			Token.CommitTran()
		End Sub

	End Module
End Namespace
